package com.xcc.controller;

import com.xcc.common.ApplicationContextHelper;
import com.xcc.common.Result;
import com.xcc.dao.SysAclModuleMapper;
import com.xcc.exception.ParamException;
import com.xcc.model.SysAclModule;
import com.xcc.param.TestParam;
import com.xcc.util.BeanValidator;
import com.xcc.util.JsonMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @outhor Ren
 * @create 2019-03-19 0:01
 * 描述:
 */
@Controller
@RequestMapping("/test")
@Slf4j
public class TestController {


    @RequestMapping("/hello")
    @ResponseBody
    public String hello() {
        log.info("hello");
        return "hehllo, permission";
    }


    @RequestMapping(value = "/getResult", method = RequestMethod.GET)
    @ResponseBody
    public Result getResult(String num) {
        if (num.equals("0")) {
            throw new RuntimeException("run error");
        }
        return Result.success();
    }

    @RequestMapping(value = "/getError.page", method = RequestMethod.GET)
    @ResponseBody
    public Result getErrorPage(String num) {
        if (num.equals("0")) {
            throw new RuntimeException("page get error");
        }
        return Result.success();
    }

    @RequestMapping(value = "/validate")
    @ResponseBody
    public Result validate(String id) {
        log.error(id);

        // 通过上下文获取 dao 层对象
        SysAclModuleMapper moduleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);
        SysAclModule module = moduleMapper.selectByPrimaryKey(1);
//        BeanValidator.check(param);
        return Result.success("", JsonMapper.obj2String(module));
    }


}
